package com.mc.moring.information.modle

import com.mc.moring.app.LogUtils
import com.mc.moring.base.BaseModle
import com.mc.moring.base.HttpCallback
import com.mc.moring.netconfig.Apis
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.ResponseBody


class KycModle : BaseModle() {

    private val coroutineScope = CoroutineScope(Dispatchers.Default)

    companion object {
        val instant by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            KycModle()
        }
    }


    fun getZiLiPageUserInfoConfig(map: MutableMap<String,String>,httpCallback: HttpCallback){
        coroutineScope.launch {
            try {
                var result = ""
                val mapString = getZiLiPageJson(map, false)
                val request: RequestBody =
                    mapString.toRequestBody("application/json".toMediaTypeOrNull())
                val data = Apis.apiKycServer.getZiLiPageUserInfoConfig(request)
                val responseBody: ResponseBody? = data.body()
                result = decryptingZiLiPageData(data)
                LogUtils.logE("e ：$result")
                httpCallback.onSuccess(result)
            } catch (e: Exception) {
                LogUtils.logE("e ：$e")
            }
        }
    }

    fun getZiLiPageUserFullInfo(map: MutableMap<String,String>,httpCallback: HttpCallback){
        coroutineScope.launch {
            try {
                var result = ""
                val mapString = getZiLiPageJson(map, false)
                val request: RequestBody =
                    mapString.toRequestBody("application/json".toMediaTypeOrNull())
                val data = Apis.apiKycServer.getZiLiPageUserFullInfo(request)
                val responseBody: ResponseBody? = data.body()
                result = decryptingZiLiPageData(data)
                LogUtils.logE("e ：$result")
                httpCallback.onSuccess(result)
            } catch (e: Exception) {
                LogUtils.logE("e ：$e")
            }
        }
    }

    fun updateZiLiPageUserInfo(map: MutableMap<String,String>,httpCallback: HttpCallback){
        coroutineScope.launch {
            try {
                var result = ""
                val mapString = getZiLiPageJson(map, false)
                val request: RequestBody =
                    mapString.toRequestBody("application/json".toMediaTypeOrNull())
                val data = Apis.apiKycServer.updateZiLiPageUserInfo(request)
                val responseBody: ResponseBody? = data.body()
                result = decryptingZiLiPageData(data)
                LogUtils.logE("e ：$result")
                httpCallback.onSuccess(result)
            } catch (e: Exception) {
                LogUtils.logE("e ：$e")
            }
        }
    }

    fun getZiLiPagePayBankList(map: MutableMap<String,String>,httpCallback: HttpCallback){
        coroutineScope.launch {
            try {
                var result = ""
                val mapString = getZiLiPageJson(map, false)
                val request: RequestBody =
                    mapString.toRequestBody("application/json".toMediaTypeOrNull())
                val data = Apis.apiLoanServer.bankgetPayBankList(request)
                val responseBody: ResponseBody? = data.body()
                result = decryptingZiLiPageData(data)
                LogUtils.logE("e ：$result")
                httpCallback.onSuccess(result)
            } catch (e: Exception) {
                LogUtils.logE("e ：$e")
            }
        }
    }

    fun updateZiLiPageJobInfo(map: MutableMap<String,String>,httpCallback: HttpCallback){
        coroutineScope.launch {
            try {
                var result = ""
                val mapString = getZiLiPageJson(map, false)
                val request: RequestBody =
                    mapString.toRequestBody("application/json".toMediaTypeOrNull())
                val data = Apis.apiKycServer.updateZiLiPageJobInfo(request)
                val responseBody: ResponseBody? = data.body()
                result = decryptingZiLiPageData(data)
                LogUtils.logE("e ：$result")
                httpCallback.onSuccess(result)
            } catch (e: Exception) {
                LogUtils.logE("e ：$e")
            }
        }
    }

    fun updateZiLiPageList(map: MutableMap<String,Any>, httpCallback: HttpCallback){
        coroutineScope.launch {
            try {
                var result = ""
                val mapString = getZiLiPageJson(map, false)
                val request: RequestBody =
                    mapString.toRequestBody("application/json".toMediaTypeOrNull())
                val data = Apis.apiKycServer.updateZiLiPageList(request)
                val responseBody: ResponseBody? = data.body()
                result = decryptingZiLiPageData(data)
                LogUtils.logE("e ：$result")
                httpCallback.onSuccess(result)
            } catch (e: Exception) {
                LogUtils.logE("e ：$e")
            }
        }
    }
}